<#import "/layout/mainLayout.html" as mainLayout />

<#macro mainheading>

</#macro>
<#assign mainheading = mainheading in mainLayout />

<#macro maincontent>
    <section class="content">
        <div class="row">
            <div class="col-xs-12">
                <div class="box">
                    <div class="box-header">
                        <div class="row">

                            <div class="col-sm-1 pull-right">
                                <a class="btn btn-block btn-default "  href="/page/ad/add">添加
                                </a>
                            </div>

                            <!--<div class="col-sm-1 pull-right">-->
                                <!--<button class="btn btn-block btn-default " id ="btn_search" onclick="searchList()">查询-->
                                <!--</button>-->
                            <!--</div>-->
                        </div><!-- /.box-header -->
                    </div>

                    <div class="box-body table-responsive no-padding">
                        <table class="table table-hover">
                            <tbody>
                            <thead>
                            <tr>
                                <th>图像</th>
                                <th>标题</th>
                                <th>链接</th>
                                <th>类型</th>
                                <th>时间</th>
                                <th style="text-align: center">操作</th>
                            </tr>
                            </thead>
                            <tbody id="bodycontent">


                            </tbody>
                        </table>
                    </div><!-- /.box-body -->
                    <div id="pagecontent" class="pagination"></div>
                </div><!-- /.box -->
            </div>
        </div>
    </section>
</#macro>
<#assign maincontent = maincontent in mainLayout />

<#macro mainfooter>
    <!--layoutmain footer...-->
    <!--<br />-->
    <script src="/js/jquery/jquery.form.js"></script>

    <script type="text/javascript">
        var ad_data = {
        };
        function searchList() {
            ad_data = {
                type:-1,
                pno: 1,
                pagesize: 10,
                allcount:-1
            };


            LoadList();
        }
        //加载列表
        searchList();
        function LoadList() {
            $('#pagecontent').html('');
            $.ajax({
                    url: '/api/ad/getlist',
                    dataType: 'json',
                    data: ad_data,
                    success: function (data) {
                        if (mortise_layout.ValidataResult(data)) {
                            if (data.result) {
                                ad_data.allcount = data.result.count;
                                var html = '';
                                $.each(data.result.list, function (index, item) {
                                    html += getHtml(item);
                                })
                                $('#bodycontent').html(html);
                                ShowPage('pagecontent', ad_data, function (pno) {
                                    ad_data.pno = pno;
                                    LoadList();
                                });
                            }
                            else {
                                alert('返回数据错误！');
                            }
                        }
                        else {
                            alert('请求数据失败！');
                        }
                    }
                }
            );
        }
        function getTypeName(type) {
            if (type=='1'){
                return 'banner广告';
            }
            else if (type=='2') {
                return '开屏广告';
            }

        }
        function  getHtml(dataObject) {

            return ' <tr>'+
                '<td><img width="120px" height="120px" src="'+dataObject.fPhoto+'"></td>'+
                '<td>'+dataObject.fTitle+'</td>'+
                '<td>'+dataObject.fUrl+'</td>'+
                '<td>'+getTypeName(dataObject.fType)+'</td>'+
                '<td>'+dataObject.fIntime+'</td>'+
                '<td>' +
                '<a style="cursor: pointer"    href="/page/ad/update?fid='+dataObject.fId+'">修改</a>&nbsp;&nbsp;' +
                '<a style="cursor: pointer" href="#" onclick="Deletead(\''+dataObject.fId+'\')">删除</a></td>'+
                '</tr>';
        }
        
        function Deletead(id) {
            $.ajax({
                    url: '/api/ad/deletead',
                    data: {'id': id},
                    type: 'POST',
                    contentType: "application/x-www-form-urlencoded",
                    dataType: 'json',
                    success: function (data) {
                        if (data) {
                            if (data.code=='OperateOk'){
                                dialog({
                                    title:'提示',
                                    content: '操作成功！',
                                    cancel: false,
                                    ok: function () {}
                                }).width(320).showModal();
                                LoadList();
                            }
                            else{
                                dialog({
                                    title:'提示',
                                    content: '操作失败！',
                                    cancel: false,
                                    ok: function () {}
                                }).width(320).showModal();
                            }
                        }
                        else {
                            alert('请求数据失败！');
                        }
                    }
                }
            );
        }
    </script>
</#macro>
<#assign mainfooter = mainfooter in mainLayout />
<@mainLayout.page title="用户管理"/>